#include "BinaryTree.h"
#include "StackQueue.h"
void BinaryInit(BTNode* root){
    root->right=NULL;
    root->left=NULL;
    root->data=NULL;
}
int TreeSize(BTNode* root){
    return root==NULL?0: TreeSize(root->left) + TreeSize(root->right)+1;
}
int TreeLeafSize(BTNode* root){
    if (root==NULL){
        return 0;
    }
    if (root->right==NULL&&root->left==NULL){
        return 1;
    }
    return TreeLeafSize(root->left)+ TreeLeafSize(root->right);
}
//前序
void PreOrder(BTNode* root){
//    判断当前节点是否为空
    if (root==NULL){
        printf("NULL ");
        return;
    }
    printf("%c ",root->data);//打印根节点
    PreOrder(root->left);//递归左子树
    PreOrder(root->right);//递归右边子树
}
//中序
void InOrder(BTNode* root){
    if (root==NULL){
        printf("NULL ");
        return;
    }
    InOrder(root->left);
    printf("%c ",root->data);
    InOrder(root->right);

}
//右序
void PostOrder(BTNode* root){
    if (root==NULL){
        printf("NULL ");
        return;
    }
    PostOrder(root->left);
    PostOrder(root->right);
    printf("%c ",root->data);
}
//广度遍历
void Leve1Order(BTNode* root){
    Queue q;
    QueueInit(&q);
//    上一层出的时候，带下一层进
    if (root){
        QueuePush(&q,root);
    }
    while(!QueueEmpty(&q)){
        BTNode* front= QueueFront(&q);
        QueuePop(&q);
        printf("%c ",front->data);
        if (front->left){
            QueuePush(&q,front->left);
        }
        if (front->right){
            QueuePush(&q,front->right);
        }

    }
    printf("\n");
    QueueDestory(&q);
}
void TreeDestory(BTNode*root){
    if (root==NULL){
        return;
    }
    TreeDestory(root->left);
    TreeDestory(root->right);
    free(root);
    root=NULL;
}